package com.kkkkkba.search.dataSource;

import com.kkkkkba.search.model.enums.SearchTypeEnum;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


@Component
public class DataSourseRegistry {


    @Resource
    private PostDataSource postDataSource;

    @Resource
    private UserDataSource userDataSource;

    @Resource
    private PictureDataSource pictureDataSource;

    @Resource
    private VideoDataSource videoDataSource;

    @Resource
    private CodeDataSource codeDataSource;

    @Resource
    private MusicDataSource musicDataSource;

    private Map<String,DataSource> typeDataSourseMap ;

    @PostConstruct
    public void doInit(){
        typeDataSourseMap = new HashMap(){{
            put(SearchTypeEnum.POST.getValue(),postDataSource);
            put(SearchTypeEnum.USER.getValue(),userDataSource);
            put(SearchTypeEnum.PICTURE.getValue(),pictureDataSource);
            put(SearchTypeEnum.VIDEO.getValue(),videoDataSource);
            put(SearchTypeEnum.CODE.getValue(),codeDataSource);
            put(SearchTypeEnum.MUSIC.getValue(),musicDataSource);
        }};
    }

    public DataSource getDataSourceByType (String type){
        if(typeDataSourseMap == null)return null;
        return  typeDataSourseMap.get(type);
    }
}
